package com.tanhua.sso.handler;


import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;

import java.util.Date;

public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        Object created=getFieldValByName("created",metaObject);
        if(null==created){
            //字节为空, 可以进行填充
            setFieldValByName("created",new Date(),metaObject);
        }

        Object updated=getFieldValByName("updated",metaObject);
        if(null==updated){
            //字段为空,可以静心填充
            setFieldValByName("updated",new Date(),metaObject);
        }
    }

    @Override
    public void updateFill(MetaObject metaObject) {
//更新数据时,直接跟新字段
        setFieldValByName("updated",new Date(),metaObject);
    }
}
